import React from 'react';
import { connect } from 'dva';

import { Table,Button } from 'antd';

const columns = [
    {
        title: '序号',
        width: 10,
        dataIndex: 'id',
        key: 'id',
        fixed: 'left'
    },
    {
        title: '姓名',
        width: 10,
        dataIndex: 'name',
        key: 'name'
    },
    {
        title: '年龄',
        width: 10,
        dataIndex: 'age',
        key: 'age'
    },
    {
        title: '性别',
        dataIndex: 'sex',
        key: 'sex',
        width: 10,
        render:(item)=>item===true?'男':'女'
    },
    {
        title:'电话',
        dataIndex:'tel',
        key:'tel',
        width:20,
    },
    {
        title:'邮箱',
        dataIndex:'email',
        key:'email',
        width:20
    },
    {
        title: '地址',
        dataIndex: 'address',
        key: 'address',
        width: 30,
    },
    {
        title: '注册时间',
        dataIndex: 'createTime',
        key: 'createTime',
        width: 20,
    },
    {
        title: '操作',
        key: 'operation',
        fixed: 'right',
        width: 10,
        render: () => <Button type="primary" size="small">编辑</Button>,
    },
];


class UserPage extends React.Component {
    render() {
        console.log(this.props.list, '用户列表');
        return (
            <Table rowKey={item=>item.id} columns={columns} dataSource={this.props.list} scroll={{ x: 1500, y: 360 }} />
        )
    }

    componentWillMount() {
        this.props.dispatch({ type: 'user/getListAsync' });
    }
}

UserPage.propTypes = {

}
const mapStateToProps = (state) => {
    return {
        list: state.user.list
    }
}
export default connect(mapStateToProps)(UserPage);